﻿#define test

#region itdc

/************************************************************************
*Copyright(C) 2015 by qsgy
 *All rights reserved. 
 *FileName:     $safeitemname$
 *Author:       oyh
 *Version:      
 *UnityVersion：
 *Date:   $time$      
 *Description:    
 *History: 
************************************************************************/
#endregion
using Assets.Scripts.Interface;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LazerGun : AProp
{
    [Tooltip("射出的子弹类型")]
    public Shot shotType = Shot.RAY;
    [SerializeField,Tooltip("激光枪的伤害值")]
    public Damage lazerDamage;
    [SerializeField,Tooltip("发射子弹位置到人物中心的距离")]
    public float distance_Gun = 1f;
    [SerializeField,Tooltip("发射速度")]
    public float shotVelocity = 3f;
    [SerializeField, Tooltip("射击误差")]
    public float errorshot = 1f;
    private Vector3 shotV;//发射初速度通信
    private Transform[] playerTransform;//监视玩家位置
    private MoveControl playerStatus;//监视玩家状态
    

    public override void Click()
    {
        foreach (var i in playerTransform)
        {
            if (i==null)
            {
                continue;
            }

            Vector3 startPos = i.position + distance_Gun*MoveControl.eEect[(int)playerStatus.Dir];
            Helper.DebugPrint(startPos);
            shotV = MoveControl.eEect[(int)playerStatus.Dir]*shotVelocity;
            Vector3 er = Vector3.Cross(shotV, new Vector3(0, 0, 1)).normalized* UnityEngine.Random.Range(-errorshot,errorshot);

            Shots.Shot(shotV+er, startPos, (int)shotType,lazerDamage);
            base.ReduceCount(1);
        }
    }
    public override void FixedAwake()
    {
    }
    public override void Start()
    {
        base.Start();
        //初始化对玩家的监视
        var ms = (FindObjectsOfType<MoveControl>() as MoveControl[]);
        playerTransform = new Transform[ms.Length];
        for (int i = 0; i < ms.Length; i++)
        {
            playerTransform[i] = ms[i].transform;
        }
        
        playerStatus = GameManager.Instance.PlayerControl;

        //初始化发射速度
        shotV = MoveControl.eEect[(int)playerStatus.Dir];
        
    }

  

}
